package com.service.consumer.serviceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.service.consumer.service.IndexService;

@Service
public class IndexServiceImpl implements IndexService{

	@Autowired
	RestTemplate restTemplate;
	
	//断路器配置，当无法调用如下方法时，就会调用自定的HystrixError方法。
	@HystrixCommand(defaultFallback="HystrixError")
	public String index(String name){
		//远程服务调用
		return restTemplate.getForObject("http://server-01:8081/?name="+name, String.class);

	}
	
	public String HystrixError(){
		return "响应异常！";
	}
}
